package cn.wsn2018.tools.ctrl;

import cn.wsn2018.tools.model.Design.EncodeDesign;
import cn.wsn2018.tools.service.EncodeDesignService;
import cn.wsn2018.tools.util.ServletUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类名称:EncodeDesignController
 * 类描述:TODO
 * 创建人:nzx
 * 创建时间:2019/7/27 19:59
 */

@RestController
@RequestMapping("/protocol")
public class EncodeDesignController {
    @Autowired
    private EncodeDesignService encodeDesignService;

    @CrossOrigin
    @RequestMapping(value = "/encodeDesigns/designId",method = RequestMethod.GET)
    /**
     * 查询功能编码
     * @param designId
     * @param request
     * @param response
     */
    public void getEncodeDesign(@RequestParam("designId")String designId, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ServletUtil.getInstance().requestOperating(request);
        String respJson= encodeDesignService.dealEncodeDesignQueryByDesignId(designId);
        ServletUtil.getInstance().responseOperating(response, respJson);
    }

    @CrossOrigin
    @RequestMapping(value = "/encodeDesigns",method = RequestMethod.POST)
    /**
     * 保存功能编码
     * @param encodeDesign
     * @param request
     * @param response
     * @throws Exception
     */
    public void saveEncodeDesign(@RequestBody EncodeDesign encodeDesign, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ServletUtil.getInstance().requestOperating(request);
        String respJson= encodeDesignService.dealEncodeDesignSave(encodeDesign);
        ServletUtil.getInstance().responseOperating(response, respJson);
    }

    @CrossOrigin
    @RequestMapping(value = "/encodeDesigns",method = RequestMethod.PUT)
    /**
     * 修改功能编码
     * @param encodeDesign
     * @param request
     * @param response
     * @throws Exception
     */
    public void updateEncodeDesign(@RequestBody EncodeDesign encodeDesign, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ServletUtil.getInstance().requestOperating(request);
        String respJson= encodeDesignService.dealEncodeDesignUpdate(encodeDesign);
        ServletUtil.getInstance().responseOperating(response, respJson);
    }


    @CrossOrigin
    @RequestMapping(value = "/encodeDesigns/designId",method = RequestMethod.DELETE)
    /**
     * 删除功能编码
     * @param designId
     * @param request
     * @param response
     * @throws Exception
     */
    public void deleteEncodeDesign(@RequestParam("designId")String designId, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ServletUtil.getInstance().requestOperating(request);
        String respJson= encodeDesignService.dealEncodeDesignDelete(designId);
        ServletUtil.getInstance().responseOperating(response, respJson);
    }

}
